package m.jclecai.com.activity;


import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.base.BaseActivity;
import m.jclecai.com.utils.PreferenceUtil;

public class AboutUSActivity extends BaseActivity {
    @BindView(R.id.tv_name)
    TextView tvName;

    @BindView(R.id.tv_kf_number)
    TextView mTvKfNumber;

    @Override
    public int getContentView() {
        return R.layout.activity_about_us;
    }

    @Override
    public void initView() {
        leftOptionText("");
        setTitle("关于我们");
        tvName.append("\nV");
        tvName.append(getAppVersionName());

        mTvKfNumber.setText(PreferenceUtil.readString(this,PreferenceUtil.KF_NUMBER,""));
    }

    @Override
    protected void resetWindow() {
    }

    @OnClick({R.id.rl_function, R.id.rl_encourage, R.id.ll_server})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_function:
                startActivity(new Intent(AboutUSActivity.this,CompanyIntroduceActivity.class));
                break;
            case R.id.rl_encourage:
                break;
            case R.id.ll_server:
                ServicePhone();
                break;
        }
    }

    /**
     * 返回当前程序版本名
     */
    public String getAppVersionName() {
        String versionName = "1.0.0";
        try {
            // ---get the package info---
            PackageManager pm = getPackageManager();
            PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);
            versionName = pi.versionName;
//            versioncode = pi.versionCode;
            if (versionName == null || versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {
            Log.e("VersionInfo", "Exception", e);
        }
        return versionName;
    }

    /**
     * 客服电话
     */
    @OnClick(R.id.ll_server)
    void ServicePhone() {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:"+ PreferenceUtil.readString(this,PreferenceUtil.KF_NUMBER,"")));
        startActivity(intent);
    }
}
